package conf

import (
	"wespy-http-go/app/activity/common/actinfo"
	"wespy-http-go/pkg/weconfig"
	"wespy-http-go/pkg/weconfig/wenamespace/weactivity"
)

const (
	ActId = 5346 // 活动ID:5346
)

var RegionList = []string{weconfig.RegionChina}

const (
	ChipIdFlyer           = 1 // 传单
	ChipIdTipNum          = 2 // 小费
	ChipIdReputationScore = 3 // 口碑
	ChipIdBoxKey          = 4 // 宝箱钥匙
	ChipIdBuyFlag         = 5 // 购买标志
	ChipIdBoxBunddle      = 6 // 礼盒奖励包
	ChipIdJoinFlag        = 7 // 参加标志
)

const (
	StateNotOpen = 0 // 未营业
	StateOpen    = 1 // 营业中
)

const (
	DeferTaskCheckout  = "checkout"
	DeferTaskFreeFlyer = "free_flyer" // 免费传单延迟任务
)

const (
	SignTypeNormal   = 1 // 普通签到
	SignTypeAdvanced = 2 // 高级签到
)

const (
	SignStateInit     = 0 // 未开始
	SignStateComplete = 1 // 可领取
	SignStateReceived = 2 // 已领取
	SignStateExpired  = 3 // 已过期
)

type ActConfig struct {
	Activity          *weactivity.Activity `json:"-"`
	NameLength        int                  `json:"name_length"`
	ValidFlyerNumber  []int                `json:"valid_flyer_number"`
	TableNumber       int                  `json:"table_number"`
	NpcNumber         int                  `json:"npc_number"`
	NormalDuration    int                  `json:"normal_duration"`
	AdvancedDuration  int                  `json:"advanced_duration"`
	TipNum            int                  `json:"tip_num"`
	ReputationScore   int                  `json:"reputation_score"`
	FreeFlyerNumber   int                  `json:"free_flyer_number"`
	FreeFlyerDuration int                  `json:"free_flyer_duration"`
	LastFlyerDuration int                  `json:"last_flyer_duration"`

	// 排行榜相关配置
	RankStartHour    int `json:"rank_start_hour"`    // 排行榜开始时间（小时）
	RankDurationHour int `json:"rank_duration_hour"` // 排行榜持续时间（小时）

	TipsMsgHour int        `json:"tips_msg_hour"`
	SignConfig  SignConfig `json:"sign_config"`
	Messages    Messages   `json:"messages"`
}

type SignConfig struct {
	List []*DayConfig `json:"list"`
}

type DayConfig struct {
	Day            string                   `json:"day"`
	NormalReward   *weactivity.RewardConfig `json:"normal_reward"`
	AdvancedReward *weactivity.RewardConfig `json:"advanced_reward"`
}

type Messages struct {
	NameToLongMsg string             `json:"name_to_long_msg"`
	ExpiredMsg    string             `json:"expired_msg"`
	BuyBookMsg    weactivity.Message `json:"buy_book_msg"`
	FreeFlyerMsg  weactivity.Message `json:"free_flyer_msg"`
}

func GetActConfig(actInfo *weactivity.Activity) *ActConfig {
	c := new(ActConfig)
	err := actinfo.ParseSpecialInfo(actInfo, c)
	if err != nil {
		return nil
	}
	c.Activity = actInfo
	return c
}

func (c *ActConfig) GetSignDayConfig(day string) *DayConfig {
	for _, v := range c.SignConfig.List {
		if v.Day == day {
			return v
		}
	}
	return nil
}
